package com.gsdkjgpt4.sys.service.impl;

import com.gsdkjgpt4.sys.entity.Identify;
import com.gsdkjgpt4.sys.entity.User;
import com.gsdkjgpt4.sys.mapper.IdentifyMapper;
import com.gsdkjgpt4.sys.service.IIdentifyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author rendong
 * @since 2024-01-18
 */
@Service
public class IdentifyServiceImpl extends ServiceImpl<IdentifyMapper, Identify> implements IIdentifyService {

    @Override
    public Map<String, Object> selectByCode(String code) {
        if(code != null){
            //在数据库中搜索对应认证码
            Map<String, Object> data = new HashMap<>();
            List<Identify> codeInfo = this.baseMapper.selectByCode(code);
            data.put("codeInfo",codeInfo);

            //判断认证码是否正确
            data.entrySet().forEach(entry -> {
                if(entry.getValue() == null){
                    data.put("codeInfo",null);
                }
//                System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue());
            });

            //修改认证码状态
            this.baseMapper.updateStatus(code);

            return data;
        }
        return null;
    }

    @Override
    public Map<String, Object> generateCode(String code, Integer pkId) {
        Map<String, Object> data = new HashMap<>();
        this.baseMapper.generateCode(code,pkId);
        data.put("result",true);

        return data;
    }
}
